home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / keyb / pan.zip / PAN.ASM < prev    next >
Assembly Source File  |  1990-02-22  |  61KB  |  2,297 lines

  1.     title    'PAN:  Program ANimator by Pete Maclean'
  2.  
  3.     include    pan.hdr
  4.  
  5. ; Symbol definitions
  6.  
  7. CR        =    13    ; ASCII carriage return
  8. LF        =    10    ; ASCII linefeed
  9. TAB        =    9    ; ASCII Tab
  10.  
  11. ; BIOS Keyboard Buffer definitions
  12.  
  13. KBB_SEGADD    =    40h    ; segment address of buffer
  14. KBB_HEAD    =    1Ah    ; offset to head pointer
  15. KBB_TAIL    =    1Ch    ; offset to tail pointer
  16. KBB_START    =    80h    ; offset to start pointer
  17. KBB_END        =    82h    ; offset to end pointer
  18.  
  19. ; PAN States
  20.  
  21. PS_INITIAL    =    0    ; initial state - no target program loaded
  22. PS_LOADED    =    1    ; target program loaded
  23. PS_RUNNING    =    2    ; target program running
  24. PS_OBIT        =    3    ; waiting for target program to die
  25. PS_QUIT        =    4    ; QUIT pending when target program dies
  26.  
  27. code    segment    para public 'code'
  28.     assume    cs:code, ds:code
  29.     org    100h
  30. start:    jmp    main        ; entry point
  31.  
  32. ; Messages
  33.  
  34. initmsg        db    'PAN 1.0 (c) 1990 Ziff Communications Co.',CR,LF
  35.         db    'PC Magazine ',254,' Pete Maclean',CR,LF,'$'
  36.  
  37. crlfz        db    CR,LF,0
  38.  
  39. ; Definition for command-table entry
  40.  
  41. COMMAND        STRUC
  42. PC_KEY        dw    ?    ; (offset) address of command key
  43. PC_PROC        dw    ?    ; (offset) address of command processor
  44. PC_TYPE        db    ?    ; coded command type
  45. COMMAND        ENDS
  46.  
  47. command_entry_size    db    SIZE COMMAND
  48.  
  49. ; Command types
  50.  
  51. PCT_REG        =    0    ; regular command
  52. PCT_IF        =    2    ; If command
  53. PCT_ELSE    =    4    ; Else command
  54. PCT_FI        =    6    ; EndIf command
  55.  
  56. ; Command table
  57.  
  58. command_table    LABEL    COMMAND
  59.         COMMAND    <k_Break,    c_Break,    PCT_REG>
  60.         COMMAND    <k_Cursor,    c_Cursor,    PCT_REG>
  61.         COMMAND    <k_Else,    c_Else,        PCT_ELSE>
  62.         COMMAND    <k_EndIf,    c_EndIf,    PCT_FI>
  63.         COMMAND    <k_Flush,    c_Flush,    PCT_REG>
  64.         COMMAND    <k_GetKey,    c_GetKey,    PCT_REG>
  65.         COMMAND    <k_Go,        c_Go,        PCT_REG>
  66.         COMMAND    <k_IfKey,    c_IfKey,    PCT_IF>
  67.         COMMAND    <k_IfLoad,    c_IfLoad,    PCT_IF>
  68.         COMMAND    <k_IfScreen,    c_IfScreen,    PCT_IF>
  69. jump_command    COMMAND    <k_Jump,    c_Jump,        PCT_REG>
  70.         COMMAND    <k_Key,        c_Key,        PCT_REG>
  71. label_command    COMMAND    <k_Label,    c_Label,    PCT_REG>
  72.         COMMAND    <k_Load,    c_Load,        PCT_REG>
  73.         COMMAND    <k_Lock,    c_Lock,        PCT_REG>
  74.         COMMAND    <k_Mode,    c_Mode,        PCT_REG>
  75.         COMMAND    <k_Pause,    c_Pause,    PCT_REG>
  76.         COMMAND    <k_Output,    c_Output,    PCT_REG>
  77.         COMMAND    <k_Quit,    c_Quit,        PCT_REG>
  78.         COMMAND    <k_Screen,    c_Screen,    PCT_REG>
  79. setif_command    COMMAND    <k_SetIf,    c_SetIf,    PCT_REG>
  80.         COMMAND    <k_TypeRate,    c_TypeRate,    PCT_REG>
  81.         COMMAND    <k_Unlock,    c_Unlock,    PCT_REG>
  82.         COMMAND    <k_Video,    c_Video,    PCT_REG>
  83.         COMMAND    <k_WaitChild,    c_WaitChild,    PCT_REG>
  84.         COMMAND    <k_WaitScreen,    c_WaitScreen,    PCT_REG>
  85.         COMMAND    <k_WaitUntil,    c_WaitUntil,    PCT_REG>
  86.         COMMAND    <k_Wipe,    c_Wipe,        PCT_REG>
  87.  
  88. JUMP_INDEX    =    (jump_command - command_table) / SIZE COMMAND
  89. LABEL_INDEX    =    (label_command - command_table) / SIZE COMMAND
  90. SETIF_INDEX    =    (setif_command - command_table) / SIZE COMMAND
  91.  
  92. ; Command keywords
  93.  
  94. command_keys    LABEL    BYTE
  95. k_Break        db    "Break",0
  96. k_Cursor    db    "Cursor",0
  97. k_Else        db    "Else",0
  98. k_EndIf        db    "EndIf",0
  99. k_Flush        db    "Flush",0
  100. k_GetKey    db    "GetKey",0
  101. k_Go        db    "Go",0
  102. k_IfKey        db    "IfKey",0
  103. k_IfLoad    db    "IfLoad",0
  104. k_IfScreen    db    "IfScreen",0
  105. k_Jump        db    "Jump",0
  106. k_Key        db    "Key",0
  107. k_Label        db    "Label",0
  108. k_Load        db    "Load",0
  109. k_Lock        db    "Lock",0
  110. k_Mode        db    "Mode",0
  111. k_Pause        db    "Pause",0
  112. k_Output    db    "Output",0
  113. k_Quit        db    "Quit",0
  114. k_Screen    db    "Screen",0
  115. k_SetIf        db    " SetIf",0        ; cannot be written
  116. k_TypeRate    db    "TypeRate",0
  117. k_Unlock     db    "Unlock",0
  118. k_Video        db    "Video",0
  119. k_WaitChild    db    "WaitChild",0
  120. k_WaitScreen    db    "WaitScreen",0
  121. k_WaitUntil    db    "WaitUntil",0
  122. k_Wipe        db    "Wipe",0
  123.         db    0        ; end of table marker
  124.  
  125. ; Key table for "On"/"Off" arguments:
  126.  
  127. on_off        db    'OFF',0,'ON',0,0    ; Off is 0, On is 1
  128.  
  129. ; Dispatch table for preprocessing commands by type
  130.  
  131. preprocessing_table    LABEL    WORD
  132.         dw    pp_regular, pp_If, pp_Else, pp_EndIf
  133.  
  134. ; Extra dispatch table for conditional commands
  135.  
  136. n_table        dw    n_Nop, n_If, c_Else, c_EndIf
  137.  
  138. ; Miscellaneous stuff
  139.  
  140. pan_extension    db    '.PAN',0    ; Standard extension for Pan scripts
  141. pan_sp        dw    0        ; SP on transferring to a child program
  142. break_condition    db    0        ; ? break on or off
  143. command_ptr    dw    script_buffer
  144. current_command    dw    0        ; pointer to current command in script_buffer
  145. file_handle    dw    ?        ; handle for command file
  146. if_condition    db    0        ; IF condition
  147. if_effect_level    db    0        ; Level at which last If was TRUE
  148. if_nest_level    db    0        ; IF condition level
  149. in_pan_flag    db    0        ; set non-zero when in Pan timer intercept
  150. keyboard_feed    db    0        ; set when PAN needs exclusive access
  151.                     ; to the keyboard
  152. keyboard_state    db    0        ; 0 => unlocked, 1 => locked
  153. kbb_segment    dw    KBB_SEGADD    ; memory segment of keyboard buffer
  154. line_buffer    db    128 dup (?)    ; buffer for reading text through
  155. pan_state    db    PS_INITIAL    ; see list of PS_xxxx states above
  156. screen_columns    db    0        ; number of columns displayed in current video mode
  157. recall_address    dw    0        ; address to recall after timer expiry
  158. time_out    dw    0        ; time_out counter (ticks)
  159. type_rate    dw    0        ; simulation rate for typing
  160. va        db    70h        ; video attribute, default like DOS MDA
  161. video_segment    dw    0        ; memory segment address of video buffer
  162.  
  163. ; Saved BIOS-keyboard interrupt vector
  164.  
  165. i_BIOS_kb    LABEL    dword    
  166. x_bk_offset    dw    0
  167. x_bk_segment    dw    0
  168.  
  169. ; Saved timer interrupt vector
  170.  
  171. i_timer        LABEL    dword
  172. x_timer_offset    dw    0
  173. x_timer_segment    dw    0
  174.  
  175. ; Saved keyboard interrupt vector
  176.  
  177. i_keyboard    LABEL    dword
  178. x_key_offset    dw    0
  179. x_key_segment    dw    0
  180.  
  181. ; Saved Ctrl-Break interrupt vector
  182.  
  183. i_ctrl_break    LABEL    dwORD
  184. x_break_offset    dw    0
  185. x_break_segment    dw    0
  186.  
  187. ; Stack pointer from intercept
  188.  
  189. callers_sp    dw    0
  190. callers_ss    dw    0
  191.  
  192. ; Last keypress obtained by a GetKey command
  193.  
  194. keypress    LABEL    WORD    
  195. key_ASCII    db    0
  196. key_scan    db    0
  197.  
  198. ; Screen position
  199.  
  200. screen_position    LABEL    word
  201. n_col        db    0    ; column number
  202. n_row        db    0    ; row number
  203.  
  204. ; "Keyboard" Input Queue pointers
  205.  
  206. kiq_first    dw    0    ; pointer to first/next character
  207.  
  208. ; Hour and minute for WaitUntil command
  209.  
  210. until_time    LABEL    WORD
  211. minute        db    0    ; minute to wait for (0 - 60)
  212. hour        db    0    ; hour to wait for (0 - 24)
  213.  
  214. ; Parameter block for DOS program-load function
  215.  
  216. parameter_block    LABEL    WORD
  217. env_seg        dw    0    ; segment of environment string
  218. p_command_line    LABEL    dwORD    ; pointer to command line
  219. command_offset    dw    0
  220. command_segment    dw    0
  221. FCB1        LABEL    dwORD    ; FCB pointers
  222. FCB1_O        dw    0
  223. FCB1_S        dw    0
  224. FCB2        LABEL    dwORD
  225. FCB2_O        dw    0
  226. FCB2_S        dw    0
  227. child_sp    dw    0    ; child's SP
  228. child_ss    dw    0    ; child's SS
  229. child_ip    dw    0    ; child's IP
  230. child_cs    dw    0    ; child's CS
  231.  
  232. ; Other information about the child process
  233.  
  234. child_psp    dw    0    ; segment of child's PSP
  235. child_size    dw    0    ; size in paragraphs
  236.  
  237. ; Video mode table
  238.  
  239. vseg_table    LABEL    BYTE            ; Mode    Type
  240.         db    0B8h        ; 0:  CGA 40x25 b/w
  241.         db    0B8h        ; 1:  CGA 40x25 16 colors
  242.         db    0B8h        ; 2:  CGA 80x25 b/w
  243.         db    0B8h        ; 3:  CGA 80x25 16 colors
  244.         db    0        ; 4:  CGA graphics mode
  245.         db    0        ; 5:  CGA graphics mode
  246.         db    0        ; 6:  CGA graphics mode
  247.         db    0B0h        ; 7:  MDA 80x25 b/w
  248.  
  249. ; Translation table:  ASCII codes into keyboard scan codes
  250.  
  251. scan    db    03, 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50, 49, 24
  252. ;              Nul  ^A  ^B  ^C  ^D  ^E  ^F  ^G  ^H  ^I  ^J  ^K  ^L  ^M  ^N  ^O
  253.     db    25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44, 01, 26, 53, 27, 12
  254. ;        ^P  ^Q  ^R  ^S  ^T  ^U  ^V  ^W  ^X  ^Y  ^Z Esc  FS  GS  RS  US
  255.     db    57, 02, 40, 04, 05, 06, 08, 40, 10, 11, 09, 13, 51, 12, 52, 53
  256. ;        sp   !   "   #   $   %   &   '   (   )   *   +   ,   -   .   /
  257.     db    11, 02, 03, 04, 05, 06, 07, 08, 09, 10, 39, 39, 51, 13, 52, 53
  258. ;         0   1   2   3   4   5   6   7   8   9   :   ;   <   =   >   ?
  259.     db    03, 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50, 49, 24
  260. ;         @   A   B   C   D   E   F   G   H   I   J   K   L   M   N   O
  261.     db    25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44, 26, 43, 27, 07, 12
  262. ;         P   Q   R   S   T   U   V   W   X   Y   Z   [   \   ]   ^   _
  263.     db    41, 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50, 49, 24
  264. ;         `   a   b   c   d   e   f   g   h   i   j   k   l   m   n   o
  265.     db    25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44, 26, 43, 27, 41, 14
  266. ;         p   q   r   s   t   u   v   w   x   y   z   {   |   }   ~ Del
  267.  
  268. ; Translation table for special keys
  269.  
  270. keyname_list    LABEL    BYTE
  271.     db    'ESC',0,'TAB',0,'ENTER',0
  272.     db    'F1',0,'F2',0,'F3',0,'F4',0,'F5',0,'F6',0,'F7',0,'F8',0,'F9',0
  273.     db    'F10',0
  274.     db    'HOME